package br.com.yurikimo.ykkit;

import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;
import android.widget.RelativeLayout;

public class YKImage extends ImageView implements YKBaseComponent
{	
	private YKLayoutManager layoutManager;
	
	public YKImage()
	{
		super(YKDirector.getActivity());
		
		init();
	}
	
	public YKImage(float x, float y, float width, float height)
	{
		super(YKDirector.getActivity());
		
		init();
		
		setBounds(x, y, width, height);
	}
		
	private void init(){
		layoutManager = new YKLayoutManager(this);
	}
	
	public void setImage(int backgroundId)
	{
		Bitmap bitmap = YKTextureManager.loadImage(backgroundId); //BitmapFactory.decodeResource(getContext().getResources(), backgroundId);
		
		layoutManager.setObjectWidth(bitmap.getWidth());
		layoutManager.setObjectHeight(bitmap.getHeight());
		
		Drawable drawable = new BitmapDrawable(bitmap);
				
		setBackgroundDrawable(drawable);
		
		refreshLayout();
	}

	public void addToLayout(RelativeLayout relativeLayout)
	{
		layoutManager.addToLayout(relativeLayout);
	}

	public RelativeLayout getLayoutView()
	{
		return layoutManager.getLayoutView(getContext());
	}

	public YKContainer getObjectParent()
	{
		return layoutManager.getObjectParent();
	}

	public float getObjectWidth(){
		return layoutManager.getObjectWidth();
	}
	
	public float getObjectHeight(){
		return layoutManager.getObjectHeight();
	}
	
	public float getObjectX(){
		return layoutManager.getObjectX();
	}
	
	public float getObjectY(){
		return layoutManager.getObjectY();
	}

	public void refreshLayout()
	{
		layoutManager.refreshLayout();
	}

	public void removeFromSuperView()
	{
		layoutManager.removeFromSuperView();
	}

	public void setBounds(float x, float y, float width, float height)
	{
    layoutManager.setBounds(x, y, width, height);
	}

	public void setObjectParent(YKContainer parent)
	{
		layoutManager.setObjectParent(parent);
	}

	public void setPosition(float x, float y)
	{
		layoutManager.setPosition(x, y);	
	}
}
